using UnityEngine;
using System.Collections;

public enum Wall { none, top, bottom, right, left };

namespace Model
{
    public class Ball
    {
        public Vector2 position = new Vector2(0.5f, 0.5f);
        public Vector2 velocity = new Vector2(0.2f, 0.4f);
        private float radius = 0.025f;

        public Wall savedCollision;
        public Vector2 visualPosition;

        public float wallPositionRight;
        public float wallPositionLeft;
        public float wallPositionTop;
        public float wallPositionBottom;

        public float Radius
        {
            get { return this.radius; }
            set { this.radius = value; }
        }

        public Vector2 Position
        {
            get { return this.position; }
            set { this.position = value; }
        }

        public Vector2 Velocity
        {
            get { return this.velocity; }
            set { this.velocity = value; }
        }

        /// <summary>
        /// Default construct.
        /// </summary>
        public Ball()
        {
            // Default construct.
        }

        /// <summary>
        /// Creates a ball with desired attributes.
        /// </summary>
        /// <param name="startPosition">Startposition as a Vector2</param>
        /// <param name="velocity">Velocity as Vector2</param>
        /// <param name="radius">Radius as float</param>
        public Ball(int seed)
        {
            System.Random rand = new System.Random(seed);
            this.velocity = new Vector2(((float)rand.NextDouble() - 0.5f), ((float)rand.NextDouble() - 0.5f));
            // normalize to get it spherical vector with length 1.0
            this.velocity.Normalize();
            // add random length between 0 to maxSpeed
            float maxSpeed = 0.4f;
            float minSpeed = 0.2f;
            this.velocity *= minSpeed + (float)rand.NextDouble() * (maxSpeed - minSpeed);
        }

        public Ball(Vector2 startPosition, Vector2 velocity, float radius)
        {
            this.position = startPosition;
            this.velocity = velocity;
            Radius = radius;
        }
    }
}